package com.zzh.takeoutapp.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.base.MyBaseAdapter;
import com.zzh.takeoutapp.model.OrderShopBean;
import com.zzh.takeoutapp.utils.ImageManager;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/8/4.
 */

public class OrderShopAdapter extends MyBaseAdapter<OrderShopBean, OrderShopAdapter.ViewHolder> {
    private List<OrderShopBean> orderShopBeanList;

    public OrderShopAdapter(List<OrderShopBean> list, Context context) {
        super(list, context);
        this.orderShopBeanList = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup container, int type) {
        return new ViewHolder(LayoutInflater.from(context)
                .inflate(R.layout.item_order_shop, container, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        OrderShopBean orderShopBean = orderShopBeanList.get(position);
        ImageManager.loadUrlImage(context, orderShopBean.getPhoto(), holder.iv_shop_picture);
        holder.tv_title.setText(orderShopBean.getTitle());
        holder.tv_price.setText("￥"+orderShopBean.getPrice());
        holder.tv_num.setText("X" + orderShopBean.getNum());
        holder.tv_oldprices.setText("X" + orderShopBean.getOldprices());
        holder.tv_oldprices.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG );
    }

    //普通的Holder
    public class ViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_shop_picture)
        ImageView iv_shop_picture;
        @Bind(R.id.tv_title)
        TextView tv_title;
        @Bind(R.id.tv_price)
        TextView tv_price;
        @Bind(R.id.tv_num)
        TextView tv_num;
        @Bind(R.id.tv_oldprices)
        TextView tv_oldprices;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
